#!/bin/make
#
# hash - makefile for FNV hash tools
#
# @(#) $Revision: 3.21 $
# @(#) $Id: Makefile,v 3.21 2003/10/03 20:36:26 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/fnv/RCS/Makefile,v $
#
# See:
#	http://www.isthe.com/chongo/tech/comp/fnv/index.html
#
# for the most up to date copy of this code and the FNV hash home page.
#
# Please do not copyright this code.  This code is in the public domain.
#
# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# By:
#	chongo <Landon Curt Noll> /\oo/\
#	http://www.isthe.com/chongo/
#
# Share and Enjoy!	:-)

# make tools
#
SHELL= /bin/sh
CFLAGS= -O3 -g3
#CFLAGS= -O2 -g3
#CC= cc
AR= ar
TAR= tar
EGREP= egrep
GZIP_BIN= gzip
INSTALL= install

# If your system needs ranlib use:
#	RANLIB= ranlib
# otherwise use:
#	RANLIB= :
#
#RANLIB= ranlib
RANLIB= :

# where to install things
#
DESTBIN= /usr/local/bin
DESTLIB= /usr/local/lib
DESTINC= /usr/local/include
# NOTE: Lines with WWW in them are removed from the shipped Makefile
WWW= /web/isthe/chroot/html/chongo/src/fnv

# what to build
#
SRC=	hash_32.c hash_32a.c hash_64.c hash_64a.c \
	fnv32.c fnv32a.c fnv64.c fnv64a.c \
	have_ulong64.c
HSRC=	fnv.h \
	longlong.h
ALL=	${SRC} ${HSRC} \
	README Makefile
PROGS=	fnv032 fnv064 fnv0_32 fnv0_64 fnv132 fnv164 fnv1_32 fnv1_64 \
	fnv1a32 fnv1a64 fnv1a_32 fnv1a_64
LIBS=	libfnv.a
LIBOBJ=	hash_32.o hash_64.o hash_32a.o hash_64a.o
OTHEROBJ= fnv32.o fnv64.o fnv32a.o fnv64a.o
TARGETS= ${LIBOBJ} ${LIBS} ${PROGS}

# default rule
#
all: ${TARGETS}

# things to build
#
hash_32.o: hash_32.c longlong.h fnv.h
	${CC} ${CFLAGS} hash_32.c -c

hash_64.o: hash_64.c longlong.h fnv.h
	${CC} ${CFLAGS} hash_64.c -c

hash_32a.o: hash_32a.c longlong.h fnv.h
	${CC} ${CFLAGS} hash_32a.c -c

hash_64a.o: hash_64a.c longlong.h fnv.h
	${CC} ${CFLAGS} hash_64a.c -c

libfnv.a: ${LIBOBJ}
	rm -f $@
	${AR} rv $@ ${LIBOBJ}
	${RANLIB} $@

fnv32.o: fnv32.c longlong.h fnv.h
	${CC} ${CFLAGS} fnv32.c -c

fnv32a.o: fnv32a.c longlong.h fnv.h
	${CC} ${CFLAGS} fnv32a.c -c

fnv032: fnv32.o libfnv.a
	${CC} fnv32.o libfnv.a -o fnv032

fnv1a32: fnv32a.o libfnv.a
	${CC} fnv32a.o libfnv.a -o fnv1a32

fnv64.o: fnv64.c longlong.h fnv.h
	${CC} ${CFLAGS} fnv64.c -c

fnv64a.o: fnv64a.c longlong.h fnv.h
	${CC} ${CFLAGS} fnv64a.c -c

fnv064: fnv64.o libfnv.a
	${CC} fnv64.o libfnv.a -o fnv064

fnv1a64: fnv64a.o libfnv.a
	${CC} fnv64a.o libfnv.a -o fnv1a64

fnv0_32: fnv032
	-rm -f $@
	-cp -f $? $@

fnv0_64: fnv064
	-rm -f $@
	-cp -f $? $@

fnv132: fnv032
	-rm -f $@
	-cp -f $? $@

fnv164: fnv064
	-rm -f $@
	-cp -f $? $@

fnv1_32: fnv032
	-rm -f $@
	-cp -f $? $@

fnv1_64: fnv064
	-rm -f $@
	-cp -f $? $@

fnv1a_32: fnv1a32
	-rm -f $@
	-cp -f $? $@

fnv1a_64: fnv1a64
	-rm -f $@
	-cp -f $? $@

longlong.h: have_ulong64.c Makefile
	-@rm -f have_ulong64 have_ulong64.o ll_tmp longlong.h
	@echo 'forming longlong.h'
	@echo '/*' > longlong.h
	@echo ' * DO NOT EDIT -- generated by the Makefile' >> longlong.h
	@echo ' */' >> longlong.h
	@echo '' >> longlong.h
	@echo '#if !defined(__LONGLONG_H__)' >> longlong.h
	@echo '#define __LONGLONG_H__' >> longlong.h
	@echo '' >> longlong.h
	@echo '/* do we have/want to use a long long type? */' >> longlong.h
	-@rm -f have_ulong64.o have_ulong64
	-@${CC} ${CFLAGS} have_ulong64.c -c 2>/dev/null; true
	-@${CC} ${CFLAGS} have_ulong64.o -o have_ulong64 2>/dev/null; true
	-@${SHELL} -c "./have_ulong64 > ll_tmp 2>/dev/null" \
	    >/dev/null 2>&1; true
	-@if [ -s ll_tmp ]; then \
	    cat ll_tmp >> longlong.h; \
	else \
	    echo '#undef HAVE_64BIT_LONG_LONG	/* no */' >> longlong.h; \
	fi
	@echo '' >> longlong.h
	@echo '#endif /* !__LONGLONG_H__ */' >> longlong.h
	-@rm -f have_ulong64 have_ulong64.o ll_tmp
	@echo 'longlong.h formed'

# utilities
#
install: all
	-@if [ -d "${DESTBIN}" ]; then \
	    echo "	mkdir -p ${DESTBIN}"; \
	    mkdir -p ${DESTBIN}; \
	fi
	-@if [ -d "${DESTLIB}" ]; then \
	    echo "	mkdir -p ${DESTLIB}"; \
	    mkdir -p ${DESTLIB}; \
	fi
	-@if [ -d "${DESTINC}" ]; then \
	    echo "	mkdir -p ${DESTINC}"; \
	    mkdir -p ${DESTINC}; \
	fi
	${INSTALL} -m 0755 ${PROGS} ${DESTBIN}
	${INSTALL} -m 0644 ${LIBS} ${DESTLIB}
	${RANLIB} ${DESTLIB}/libfnv.a
	${INSTALL} -m 0644 ${HSRC} ${DESTINC}
	@# NOTE: Lines with WWW in them are removed from the shipped Makefile
	-@if [ -d ${WWW} ]; then \
	    echo "rm -f Makefile.ship";			: WWW; \
	    rm -f Makefile.ship;			: WWW; \
	    echo "${EGREP} -v WWW Makefile > Makefile.ship"; 	: WWW; \
	    ${EGREP} -v WWW Makefile > Makefile.ship; 	: WWW; \
	    echo "rm -f Makefile.save";			: WWW; \
	    rm -f Makefile.save;			: WWW; \
	    echo "ln Makefile Makefile.save";		: WWW; \
	    ln Makefile Makefile.save;			: WWW; \
	    echo "cp -f Makefile.ship Makefile";	: WWW; \
	    cp -f Makefile.ship Makefile;		: WWW; \
	    echo "${TAR} -cf - ${ALL} | ${GZIP_BIN} --best > fnv_hash.tar.gz";: WWW; \
	    ${TAR} -cf - ${ALL} | ${GZIP_BIN} --best > fnv_hash.tar.gz;: WWW; \
	    echo "${INSTALL} -m 0644 fnv_hash.tar.gz ${ALL} ${WWW}"; \
	    ${INSTALL} -m 0644 fnv_hash.tar.gz ${ALL} ${WWW}; \
	    echo "mv -f Makefile.save Makefile";	: WWW; \
	    mv -f Makefile.save Makefile;		: WWW; \
	    echo "rm -f fnv_hash.tar.gz Makefile.ship";	: WWW; \
	    rm -f fnv_hash.tar.gz Makefile.ship;	: WWW; \
	fi;						: WWW

clean:
	-rm -f have_ulong64 have_ulong64.o ll_tmp ll_tmp2 longlong.h
	-rm -f ${LIBOBJ}
	-rm -f ${OTHEROBJ}
	-rm -f fnv_hash.tar.gz Makefile.ship	# WWW

clobber: clean
	-rm -f ${TARGETS}

check: all
	@echo
	@echo "	These tests should not print an un-indented hash value:"
	@echo
	@echo "	fnv0_32 -s hi == 0x6800a3d1"
	-@./fnv0_32 -s hi | ${EGREP} -v 0x6800a3d1; /bin/true
	@echo "	fnv0_32 -s hello == 0xec6d6be8"
	-@./fnv0_32 -s hello | ${EGREP} -v 0xec6d6be8; /bin/true
	@echo "	fnv0_32 -s curds and whey == 0x4a83403b"
	-@./fnv0_32 -s curds and whey | ${EGREP} -v 0x4a83403b; /bin/true
	@echo "	fnv0_64 -s hi == 0x000068000000b0d1"
	-@./fnv0_64 -s hi | ${EGREP} -v 0x000068000000b0d1; /bin/true
	@echo "	fnv0_64 -s hello == 0x3fa86e63bc7d03c8"
	-@./fnv0_64 -s hello | ${EGREP} -v 0x3fa86e63bc7d03c8; /bin/true
	@echo "	fnv0_64 -s curds and whey == 0x09d2b4132bd1333b"
	-@./fnv0_64 -s curds and whey | ${EGREP} -v 0x09d2b4132bd1333b;/bin/true
	-@rm -f ll_tmp ll_tmp2
	-@echo line 1 > ll_tmp
	-@echo line 2 >> ll_tmp
	-@echo line 3 >> ll_tmp
	@echo '	echo "line 1\\nline 2\\nline 3" > ll_tmp'
	@echo "	dd if=/dev/zero bs=1024k count=4 of=ll_tmp2 >/dev/null 2>&1"
	-@dd if=/dev/zero bs=1024k count=4 of=ll_tmp2 >/dev/null 2>&1
	@echo "	fnv0_32 < ll_tmp == 0x1fad81d0"
	-@./fnv0_32 < ll_tmp | ${EGREP} -v 0x1fad81d0; /bin/true
	@echo "	fnv0_64 < ll_tmp == 0xa8cf5b7784759250"
	-@./fnv0_64 < ll_tmp | ${EGREP} -v 0xa8cf5b7784759250; /bin/true
	@echo "	fnv0_32 < ll_tmp2 == 0x00000000"
	-@./fnv0_32 < ll_tmp2 | ${EGREP} -v 0x00000000; /bin/true
	@echo "	fnv0_64 < ll_tmp2 == 0x0000000000000000"
	-@./fnv0_64 < ll_tmp2 | ${EGREP} -v 0x0000000000000000; /bin/true
	@echo "	fnv0_32 ll_tmp == 0x1fad81d0"
	-@./fnv0_32 ll_tmp | ${EGREP} -v 0x1fad81d0; /bin/true
	@echo "	fnv0_64 ll_tmp == 0xa8cf5b7784759250"
	-@./fnv0_64 ll_tmp | ${EGREP} -v 0xa8cf5b7784759250; /bin/true
	@echo "	fnv0_32 ll_tmp2 == 0x00000000"
	-@./fnv0_32 ll_tmp2 | ${EGREP} -v 0x00000000; /bin/true
	@echo "	fnv0_64 ll_tmp2 == 0x0000000000000000"
	-@./fnv0_64 ll_tmp2 | ${EGREP} -v 0x0000000000000000; /bin/true
	@echo "	fnv0_32 ll_tmp ll_tmp == 0xc500fd20"
	-@./fnv0_32 ll_tmp ll_tmp | ${EGREP} -v 0xc500fd20; /bin/true
	@echo "	fnv0_64 ll_tmp ll_tmp == 0x3c8b9c3715fc1920"
	-@./fnv0_64 ll_tmp ll_tmp | ${EGREP} -v 0x3c8b9c3715fc1920; /bin/true
	@echo "	fnv0_32 ll_tmp ll_tmp2 == 0x6fad81d0"
	-@./fnv0_32 ll_tmp ll_tmp2 | ${EGREP} -v 0x6fad81d0; /bin/true
	@echo "	fnv0_64 ll_tmp ll_tmp2 == 0x29a78f5dd4759250"
	-@./fnv0_64 ll_tmp ll_tmp2 | ${EGREP} -v 0x29a78f5dd4759250; /bin/true
	@echo "	fnv0_32 ll_tmp2 ll_tmp == 0x1fad81d0"
	-@./fnv0_32 ll_tmp2 ll_tmp | ${EGREP} -v 0x1fad81d0; /bin/true
	@echo "	fnv0_64 ll_tmp2 ll_tmp == 0xa8cf5b7784759250"
	-@./fnv0_64 ll_tmp2 ll_tmp | ${EGREP} -v 0xa8cf5b7784759250; /bin/true
	@echo "	fnv0_32 ll_tmp2 ll_tmp2 == 0x00000000"
	-@./fnv0_32 ll_tmp2 ll_tmp2 | ${EGREP} -v 0x00000000; /bin/true
	@echo "	fnv0_64 ll_tmp2 ll_tmp2 == 0x0000000000000000"
	-@./fnv0_64 ll_tmp2 ll_tmp2 | ${EGREP} -v 0x0000000000000000; /bin/true
	@echo
	@echo "	fnv1_32 -s hi == 0x6977223c"
	-@./fnv1_32 -s hi | ${EGREP} -v 0x6977223c; /bin/true
	@echo "	fnv1_32 -s hello == 0xb6fa7167"
	-@./fnv1_32 -s hello | ${EGREP} -v 0xb6fa7167; /bin/true
	@echo "	fnv1_32 -s curds and whey == 0x08ebf912"
	-@./fnv1_32 -s curds and whey | ${EGREP} -v 0x08ebf912; /bin/true
	@echo "	fnv1_64 -s hi == 0x08326007b4eb2b9c"
	-@./fnv1_64 -s hi | ${EGREP} -v 0x08326007b4eb2b9c; /bin/true
	@echo "	fnv1_64 -s hello == 0x7b495389bdbdd4c7"
	-@./fnv1_64 -s hello | ${EGREP} -v 0x7b495389bdbdd4c7; /bin/true
	@echo "	fnv1_64 -s curds and whey == 0x795ad7b2d9a7dc72"
	-@./fnv1_64 -s curds and whey | ${EGREP} -v 0x795ad7b2d9a7dc72;/bin/true
	@echo "	fnv1_32 < ll_tmp == 0xb8cbeb33"
	-@./fnv1_32 < ll_tmp | ${EGREP} -v 0xb8cbeb33; /bin/true
	@echo "	fnv1_64 < ll_tmp == 0x79dcad190c3291b3"
	-@./fnv1_64 < ll_tmp | ${EGREP} -v 0x79dcad190c3291b3; /bin/true
	@echo "	fnv1_32 < ll_tmp2 == 0xce1c9dc5"
	-@./fnv1_32 < ll_tmp2 | ${EGREP} -v 0xce1c9dc5; /bin/true
	@echo "	fnv1_64 < ll_tmp2 == 0xf8e3e56ce9222325"
	-@./fnv1_64 < ll_tmp2 | ${EGREP} -v 0xf8e3e56ce9222325; /bin/true
	@echo "	fnv1_32 ll_tmp == 0xb8cbeb33"
	-@./fnv1_32 ll_tmp | ${EGREP} -v 0xb8cbeb33; /bin/true
	@echo "	fnv1_64 ll_tmp == 0x79dcad190c3291b3"
	-@./fnv1_64 ll_tmp | ${EGREP} -v 0x79dcad190c3291b3; /bin/true
	@echo "	fnv1_32 ll_tmp2 == 0xce1c9dc5"
	-@./fnv1_32 ll_tmp2 | ${EGREP} -v 0xce1c9dc5; /bin/true
	@echo "	fnv1_64 ll_tmp2 == 0xf8e3e56ce9222325"
	-@./fnv1_64 ll_tmp2 | ${EGREP} -v 0xf8e3e56ce9222325; /bin/true
	@echo "	fnv1_32 ll_tmp ll_tmp == 0x08ae22e5"
	-@./fnv1_32 ll_tmp ll_tmp | ${EGREP} -v 0x08ae22e5; /bin/true
	@echo "	fnv1_64 ll_tmp ll_tmp == 0x10a587a0ff68f305"
	-@./fnv1_64 ll_tmp ll_tmp | ${EGREP} -v 0x10a587a0ff68f305; /bin/true
	@echo "	fnv1_32 ll_tmp ll_tmp2 == 0x23cbeb33"
	-@./fnv1_32 ll_tmp ll_tmp2 | ${EGREP} -v 0x23cbeb33; /bin/true
	@echo "	fnv1_64 ll_tmp ll_tmp2 == 0xcafae19b7f3291b3"
	-@./fnv1_64 ll_tmp ll_tmp2 | ${EGREP} -v 0xcafae19b7f3291b3; /bin/true
	@echo "	fnv1_32 ll_tmp2 ll_tmp == 0x1fcbeb33"
	-@./fnv1_32 ll_tmp2 ll_tmp | ${EGREP} -v 0x1fcbeb33; /bin/true
	@echo "	fnv1_64 ll_tmp2 ll_tmp == 0x06319755db3291b3"
	-@./fnv1_64 ll_tmp2 ll_tmp | ${EGREP} -v 0x06319755db3291b3; /bin/true
	@echo "	fnv1_32 ll_tmp2 ll_tmp2 == 0x1b1c9dc5"
	-@./fnv1_32 ll_tmp2 ll_tmp2 | ${EGREP} -v 0x1b1c9dc5; /bin/true
	@echo "	fnv1_64 ll_tmp2 ll_tmp2 == 0x637a2df54e222325"
	-@./fnv1_64 ll_tmp2 ll_tmp2 | ${EGREP} -v 0x637a2df54e222325; /bin/true
	@echo
	-@rm -f ll_tmp ll_tmp2
	@echo "	All done!"
